home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Reference Guide / C-C++ Interactive Reference Guide.iso / c_ref / csource5 / 311_01 / rtest.c < prev    next >
C/C++ Source or Header  |  1990-04-23  |  4KB  |  115 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      rtest.c  v1.3  (c) 1990  Ken Harris                                 */
  5. /*                                                                          */
  6. /*                                                                          */
  7. /****************************************************************************/
  8. /*                                                                          */
  9. /*      This software is made available on an AS-IS basis. Unrestricted     */
  10. /*      use is granted provided that the copyright notice remains intact.   */
  11. /*      The author makes no warranties expressed or implied.                */
  12. /*                                                                          */
  13. /****************************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include "db.h"
  17.  
  18. main()
  19. {
  20.         DATA_SET ds;
  21.         char     data[50];
  22.         int      i;
  23.  
  24.         printf("rtest - Test random file routines\n\n");
  25.         rcreate();
  26.         printf("...test file created...\n\n");
  27.  
  28.         ds = db_open("", "rtest.dat");
  29.         if (db_error)
  30.         {       printf("Open Failure - %s\n", db_error_msg(db_error));
  31.                 exit(0);
  32.         }
  33.  
  34.         printf("...adding 100 records...\n");
  35.         for (i=1; i<100; i++)
  36.         {       printf("%d\n",i);
  37.                 sprintf(data,"%05d",i);
  38.                 db_add(ds, data);
  39.                 if (db_error)
  40.                 {       printf("Add Failure - %s\n", db_error_msg(db_error));
  41.                         exit(0);
  42.                 }
  43.         }
  44.         printf("...add complete...\n\n");
  45.  
  46.     printf("...read forward...\n");
  47.     db_read_first(ds, data);
  48.     while (!db_error)
  49.     {    printf("%5.5s\n", data);
  50.         db_read_next(ds, data);
  51.     }
  52.     printf("...read forward complete...\n\n");
  53.  
  54.     printf("...read reverse...\n");
  55.     db_read_last(ds, data);
  56.     while (!db_error)
  57.     {    printf("%5.5s\n", data);
  58.         db_read_prev(ds, data);
  59.     }
  60.     printf("...read reverse complete...\n\n");
  61.  
  62.         printf("...find and delete...\n");
  63.         for (i=1; i<100; i++)
  64.         {       printf("%d\n",i);
  65.                 sprintf(data,"%05d",i);
  66.  
  67.                 db_find(ds, data, data);
  68.                 if (db_error)
  69.                         printf("Find Failure - %s\n", db_error_msg(db_error));
  70.  
  71.                 db_delete(ds);
  72.                 if (db_error)
  73.                         printf("Delete Failure - %s\n", db_error_msg(db_error));
  74.  
  75.         }
  76.         printf("...find and delete complete...\n\n");
  77.  
  78.         printf("...adding 100 records (again) ...\n");
  79.         for (i=1; i<100; i++)
  80.         {       printf("%d\n",i);
  81.                 sprintf(data,"%05d",i);
  82.                 db_add(ds, data);
  83.                 if (db_error)
  84.                 {       printf("Add Failure - %s\n", db_error_msg(db_error));
  85.                         exit(0);
  86.                 }
  87.         }
  88.         printf("...add complete...\n\n");
  89.  
  90.         db_close(ds);
  91.         unlink("rtest.dat");
  92. }
  93.  
  94. /*
  95.  *      rcreate - create our test random file
  96.  */
  97.  
  98. rcreate()
  99. {
  100.         DATA_SET ds;
  101.  
  102.  
  103.         ds = db_create("", "rtest.dat", "ran,rec=50,base=7,key=5");
  104.         if (db_error)
  105.         {       printf("Create Failure - %s\n", db_error_msg(db_error));
  106.                 exit(0);
  107.         }
  108.  
  109.         db_close(ds);
  110.         if (db_error)
  111.         {       printf("Close Failure - %s\n", db_error_msg(db_error));
  112.                 exit(0);
  113.         }
  114. }
  115.